package com.wy2cloud.core.exception;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;

import com.wy2cloud.core.response.ResponseResult;

/**
 * Rest控制器 异常全局处理基类   @ControllerAdvice(annotations = {RestController.class})
 * @author wuyy
 *
 */
public abstract class RestBaseGlobalExceptionAdvice extends BaseGlobalExceptionAdvice {

	/**
     * 全局处理Exception
     * 错误的情况下返回500
     * @param req
     * @param ex
     * @return
     */
    @ExceptionHandler(value = {Exception.class})
    public ResponseEntity<Object> handleExceptions(HttpServletRequest req, Exception ex) {
        Logger log= getExceptionClassLogger(ex);
        String requestUrl=req.getRequestURI();
        log.error("["+requestUrl+"]发生异常",ex);

        ResponseResult<String> tResult = new ResponseResult<String>();
        tResult.setStatus("500");
        tResult.setMessage(getError());
        return new ResponseEntity<Object>(tResult, HttpStatus.INTERNAL_SERVER_ERROR);
    }

}
